#include <set>
#include <boost/test/minimal.hpp>
#include <kuai/sim/simjob.hpp>


using namespace kuai;

class TestSimulationEnvironment
	: public kuai::SimulationEnvironment
{
public:
	void setTID(size_t id) {
		tid = id;
	}
	void setJob(SimulationJob* pjob) {
		job = pjob;
	}
};
int test_main(int, char* []) {

	std::cout << sizeof(kuai::Index) << std::endl;
	SimulationJob job;
	srand(time(NULL));
	for (size_t k = 0; k < 1000; ++k) {
		int n = rand();
		for (size_t i = 2; i < 100; ++i) {
			job.setCPU(i);
			TestSimulationEnvironment env;
			env.setJob(&job);
			size_t last_range = 0;
			std::set<size_t> size;
			size_t sum = 0;
			for (size_t j = 0; j < i; ++j) {
				env.setTID(j);
				std::pair<size_t, size_t> range = env.range(n);
				sum += range.second-range.first;
				size.insert(range.second-range.first);
				BOOST_CHECK(range.first == last_range);
				last_range = range.second;
			}
			BOOST_CHECK(last_range == n);
			BOOST_CHECK(sum == n);
			BOOST_CHECK(size.size() <= 2);
			if (size.size() == 2) {
				BOOST_CHECK(*(++size.begin()) - *size.begin() == 1);
			}
		}
	}

	return 0;

}